# central_system.py

import paho.mqtt.client as mqtt

class CentralSystem:
    def __init__(self, broker_ip="172.20.10.4", port=1883):
    # def __init__(self, broker_ip="localhost", port=1883):
        self.broker_ip = broker_ip
        self.port = port
        self.topic_response = "/agv/response"

        self.client = mqtt.Client()
        self.client.on_connect = self.on_connect
        self.client.connect(self.broker_ip, self.port, 60)

    def on_connect(self, client, userdata, flags, rc):
        print("Central System Connected")

    def run(self):
        self.client.loop_start()
        while True:
            cmd = input("Enter to start AGV: ").strip()
            if cmd == "":
                self.client.publish(self.topic_response, "START")
                print("Sent START signal to AGV.")

if __name__ == "__main__":
    system = CentralSystem()
    system.run()
